home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01a.txt
/
000055_icon-group-sender _Mon Jun 12 08:47:45 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA19788
for icon-group-addresses; Mon, 12 Jun 2000 08:47:29 -0700 (MST)
Message-Id: <200006121547.IAA19788@baskerville.CS.Arizona.EDU>
From: Steve Wampler <swampler@noao.edu>
X-Newsgroups: comp.lang.icon
Subject: Re: User defined operators for Icon
Date: Tue, 06 Jun 2000 08:36:26 -0700
X-Trace: noao.edu 960305789 18654 140.252.38.6 (6 Jun 2000 15:36:29 GMT)
X-Complaints-To: abuse@noao.edu
X-Accept-Language: en
To: icon-group@optima.CS.Arizona.EDU
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 2383
"Frank J. Lhota" wrote:
>
> Languages such as C++ and Ada permit the programmer to define the behavior
> of operators and predefined functions for user defined types. Would it be
> desirable to add such a capacity to Icon? If so, what would this facility
> look like?
Well, I have an opinion, though unicon is probably the place to pursue this,
as I don't see any major enhancements being made to Icon right now. Perhaps
whatever works in unicon could be backed into Icon later.
There are several parts (others probably have better ways to do this):
(1) Have keywords for every function (as apposed to procedures) that
always get you the "original" definition. This would be useful
now as it would allow access to the original functions even when
procedure definitions attach new meanings to the names. There
may be a problem where existing keywords match existing function
names - that would need to be resolved.
(2) Have keywords for every operand (e.g. &+, &:=, etc.) which would
act in the same way that string invocation of operators does now,
but always reference the original definitions for the operators.
(3) add a way to assign new definitions to operators, perhaps with
syntax:
operator "+"(a,b)
...
end
where the number of parameters determines which operation is
being redefined [could even generate compile-time error if
no such operation exists].
So, adding complex numbers could be (well, you could do better
than this, but it's a start):
operator +(a,b)
if (type(a) == "complex") & (type(b) == "complex") then {
return complex(a.x + b.x, a.y + b.y)
# or: return complex( &+(a.x, b.x), &+(a.y,b.y))
}
return &+(a,b)
end
Or course, unicon, with its inheritance, may be able to provide
considerably more flexibility, since the above scheme only allows
one level of redefinition...
Why do I like this?:
(a) most of the mechanisms for implementing this are already in place.
(b) there are minimal syntactic changes to the language (even less if
you go with using the reserved work "procedure" instead of adding
the reserved work "operator").
(c) with proper implementation, there should be little, if any,
performance penalty involved.
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu